import React, { Component } from 'react'

export default class App extends Component {
  state = {
    num: 0,
  }
  handleClick = () => {
    this.setState({ num: this.state.num + 1 }, () => {
      // 在回调函数里面可以拿到更新之后的数据
      console.log(this.state.num)
    })
    /* this.setState({ num: this.state.num + 1 })
    this.setState({ num: this.state.num + 2 })
    this.setState({ num: this.state.num + 3 })
    /* {
      ...{ num: this.state.num + 1 },
      ...{ num: this.state.num + 2 },
      ...{ num: this.state.num + 3 }
    } */
    // console.log(this.state.num) // 0!!! */
  }
  render() {
    return (
      <div>
        <p>App: {this.state.num}</p>
        {/* onClick => 合成事件 */}
        <button onClick={this.handleClick}>+1</button>
      </div>
    )
  }
  componentDidUpdate() {
    console.log(this.state.num)
  }
}
